package com.miyake.server.dsaccess;

import java.util.List;

import javax.jdo.PersistenceManager;

import com.miyake.server.DsNode;
import com.miyake.server.PMF;

public class GetSomething<T> {
	private T ret;
	void update(T object){};
	
	public GetSomething(String nodeKey, String className) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			String query = "select from " + DsNode.class.getName() + 
				" where key == " + "\'" + nodeKey + "\'";;

			List<DsNode> list = (List<DsNode>) pm.newQuery(query).execute();
			
			query = "select from " + className + 
			" where key == " + "\'" + list.get(0).getSubstKey() + "\'";
			List<T> list2 = (List<T>) pm.newQuery(query).execute();
			list2.size();
			ret = list2.get(0);
			update(ret);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			pm.close();
		}			
	}
	
	public T getObject() {
		return ret;
	}
}
